/**
 * Created by kule on 2017/7/3.
 */
import {flatObj} from './flatObj';
import mapSet from './mapSet';

const diffObj=function(data,target){
    let item;
    let tItem;
    const rst={};
    for(var k in target){
        item=data[k];
        tItem=target;
        if(item===tItem){
            continue;
        }
        rst[k]=target[k];
    }
    return rst;
};

//todo:简单使用，不考虑过多情况，只适用和mergeSet合并使用的情况
export const getSetDiff=function(newData,oldData){
    const newObj=flatObj(newData);
    const oldObj=flatObj(oldData);
    return diffObj(oldObj,newObj);
};

export const diffSet=function(target,newData,oldData){
    const diff=getSetDiff(newData,oldData);
    mapSet(target,diff);
};
export default diffSet;